#!/bin/ash -efu
#
# mki-cache-copy-packages
#
# This file is part of mkimage
# Copyright (C) 2007-2009  Alexey Gladkov <gladkov.alexey@gmail.com>
#
# This file is covered by the GNU General Public License,
# which should be included with mkimage as the file COPYING.
#

pkgboxdir="${PKGBOX:?directory required}"

pkgbox="$pkgboxdir/aptbox"

payload() {
	stat --printf='%A\t%s\t%Y\n' "$makefile"

	if [ -d "$pkgbox/var" ]; then
		cd "$pkgbox/var"
		find -name '*_release' -exec cat '{}' '+'
		cd - >/dev/null
	fi

	local r
	for r in ${IMAGE_PACKAGES:-} ${IMAGE_PACKAGES_REGEXP:-}; do
		if [ -f "$r" ]; then
			r="$(readlink -ev "$r")" ||
				continue
			stat --printf='%A\t%s\t%Y\n' "$r"
		else
			printf '%s\n' "$r"
		fi
	done
}
